#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define gc() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=gc();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        x*=f;
    }
}
using namespace IO;
const int N=4e5+5,mod=1e9+7;
int n,fa[N],w[N],len[N],son[N],cnt[N],ans;
vector<int> G[N];
void dfs(int p,int dep){
	len[p]=1;
	for(int v:G[p]){
		dfs(v,dep+1);
		if(len[v]+1>len[p]) len[p]=len[v]+1,son[p]=v;
	}
	++cnt[dep];
}
struct node{int a[3];}buf[N<<1],*f[N],*cur=buf;
inline void Mod(int &x){return (x>=mod)&&(x-=mod),void();}
void dp(int p){
	f[p][0].a[1]=f[p][0].a[0]=1;
	if(!son[p]) return;
	f[son[p]]=f[p]+1;
	dp(son[p]);
	int mx=0;
	for(int v:G[p])if(v^son[p]){
		f[v]=cur,cur+=len[v];
		dp(v);
		mx=max(mx,len[v]);
	}
	for(int i=1;i<=mx;++i) Mod(f[p][i].a[0]+=f[p][i].a[2]),f[p][i].a[2]=0;
	for(int v:G[p])if(v^son[p]){
		for(int i=0;i<len[v];++i){
			Mod(f[v][i].a[0]+=f[v][i].a[2]);
			node fp=f[p][i+1];
			f[p][i+1]={0,0,0};
			for(int x=0;x<=2;++x)
			for(int y=0;y<=1;++y)
				Mod(f[p][i+1].a[min(2,x+y)]+=1ll*fp.a[x]*f[v][i].a[y]%mod);
		}
	}
}
int main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i) read(fa[i]),G[fa[i]].push_back(i);
	w[0]=1;
	for(int i=1;i<=n+1;++i) w[i]=w[i-1]*2%mod;
	dfs(0,0);
	f[0]=cur,cur+=len[0];
	dp(0);
	for(int i=0;i<len[0];++i) Mod(ans+=1ll*w[n+1-cnt[i]]*f[0][i].a[1]%mod);
	cout<<ans;
	return 0;
}


